home *** CD-ROM | disk | FTP | other *** search
- /******
-
- Name: dirscan
- Author: Jim Garrison (76247,1747)
- Function: Recursively scans a DOS file directory tree structure.
-
- ******/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <dos.h>
-
- #define FNULL ((void (*)()) NULL)
- #define DNULL ((void *) NULL)
-
- long dirscan
- (
- char directory[], /* [d:][directory-path] */
- char file_mask[], /* File Name Mask */
- char attrib, /* File Attributes Mask */
- void (* dir_exit) (char *), /* Directory Exit Pointer */
- void (* file_exit)(char *,struct find_t) /* File Exit Point */
- )
-
- {
-
- unsigned rc;
- long nfiles = 0;
- struct find_t dos_find_buffer;
- char path_work[_MAX_PATH];
- char search_att;
-
- /*-- Mask off unwanted bits in attrib flags --*/
-
- search_att = attrib & (_A_HIDDEN | _A_SYSTEM);
-
- /*-- Call Directory-handling exit if specified --*/
-
- if (dir_exit != FNULL) dir_exit(directory);
-
- /*-- Build complete path to find files in current directory --*/
-
- strcpy(path_work,directory);
- strcat(path_work,file_mask);
-
- /*-- Examine "normal" files matching file_mask in cur dir --*/
-
- rc = _dos_findfirst(path_work, /* Complete path name */
- search_att, /* Normal Files only */
- &dos_find_buffer); /* Work area pointer */
-
- while(rc==0)
- {
-
- /*-- Call File-handling exit if specified --*/
-
- if (file_exit != FNULL) file_exit(directory,dos_find_buffer);
-
- /*-- Get next matching file --*/
-
- rc = _dos_findnext(&dos_find_buffer);
-
- }
-
- /*-- Now examine all sub-directories in current dir --*/
-
- strcpy(path_work,directory);
- strcat(path_work,"*.*");
-
- rc = _dos_findfirst(path_work,_A_SUBDIR,&dos_find_buffer);
-
- while(rc==0)
- {
-
- /*-- scan only subdirectory entries this time --*/
-
- if (dos_find_buffer.attrib & _A_SUBDIR)
- {
-
- /*-- skip 'parent' and 'this dir' entries --*/
-
- if (dos_find_buffer.name[0] != '.')
- {
-
- /*-- Build sub-directory path name --*/
-
- strcpy(path_work,directory);
- strcat(path_work,dos_find_buffer.name);
- strcat(path_work,"\\");
-
- /*-- Go search sub-directory recursively, --*/
- /*-- accumulating number of files examined --*/
-
- nfiles += dirscan(path_work, /* Subdir Path Name */
- file_mask, /* File Name Mask */
- attrib, /* File Attribute Mask */
- dir_exit, /* Dir Exit Routine */
- file_exit); /* File Exit Routine */
-
- }
-
- }
- else
- nfiles++;
-
- rc = _dos_findnext(&dos_find_buffer);
-
- }
-
- return(nfiles);
-
- }
-